﻿/**
 * ...
 * @author sminutoli
 */
import com.dmotiko.general.*
import com.dmotiko.meip.*
import mx.utils.Delegate;
 
class com.dmotiko.meip.Site extends com.dmotiko.general.WebSite
{
	
	private var clips:BindLibrary;
	private var aWorks:Array;
	
	public static function main():Void {
		Site.init( _root );
		
	}
	
	public static function init(timeline:MovieClip){
		if (!app) var site = new Site(timeline);
	}
	
	public static function getApp():Site {
		return Site(app);
	}
	
	function Site ( timeline:MovieClip ) {
		super(timeline);
		app = this;
		
		initSite();
	}
	
	private function initSite():Void {
		initStage();
		loadExternalData();
	}
	
	private function initStage():Void {
		Stage.scaleMode = "noScale";
		Stage.align = "TC";
	}
	
	private function loadExternalData():Void {
		var wLoader:WorksLoader = new WorksLoader();
		wLoader.addEventListener( DataXMLLoader.DATA_LOADED,  Delegate.create(this, worksLoaded) );
		wLoader.run("works.xml");
	}
	
	private function worksLoaded(e):Void 
	{
		aWorks = e.data;
		initSections();
	}
	
	public function getWorks():Array {
		return aWorks;
	}
	
	public function getClips():BindLibrary {
		return clips;
	}
	
	private function initSections():Void {
		clips = new BindLibrary( timeline );
		var s:String = _root["init_section"];
		log("Site.as | init_section= " + _root["init_section"]);
		if(s == SiteSections.HOME || s == SiteSections.NOSOTROS || s == SiteSections.PRODUCTOS || s == SiteSections.OBRAS || s == SiteSections.CLIENTES || s == SiteSections.CONTACTO) {
			setSection( s );
		} else {
			setSection( SiteSections.HOME );
		}
		
	}

	
}